package com.example.basic_ui_demo.view.news

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import coil.compose.rememberAsyncImagePainter
import coil.request.CachePolicy
import coil.request.ImageRequest
import com.example.basic_ui_demo.R

@Composable
fun bannerPainter(picUrl:String?):Painter{
    val context = LocalContext.current
    return if(picUrl == null)
        painterResource(R.drawable.error_icon)
    else{
        rememberAsyncImagePainter(
            ImageRequest
                .Builder(context)
                .data(picUrl)
                .crossfade(false)
                .allowHardware(true)
                .networkCachePolicy(CachePolicy.ENABLED)
                .memoryCachePolicy(CachePolicy.ENABLED)
                .build(),
            contentScale = ContentScale.FillBounds
        )
    }
}